#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：图灵学习 
@File    ：11.使用bs4提取文章信息.py
@IDE     ：PyCharm 
@Author  ：ChenLiGao
@Date    ：2024-11-27 10:54
'''
import requests

from bs4 import BeautifulSoup

cookies = {
    'ABTEST': '2|1732676948|v1',
    'SNUID': '895A3A75010626DD4B0107A001E82B7C',
    'SUID': '895A3B757452A20B0000000067468D54',
    'IPLOC': 'CN5000',
    'SUID': '895A3B753954A20B0000000067468D54',
    'SUV': '00514C43249C7F4967468D54F6225970',
    'ariaDefaultTheme': 'undefined',
}

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Language': 'zh,zh-CN;q=0.9',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    # 'Cookie': 'ABTEST=2|1732676948|v1; SNUID=895A3A75010626DD4B0107A001E82B7C; SUID=895A3B757452A20B0000000067468D54; IPLOC=CN5000; SUID=895A3B753954A20B0000000067468D54; SUV=00514C43249C7F4967468D54F6225970; ariaDefaultTheme=undefined',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'none',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

params = {
    '_sug_type_': '1',
    'type': '2',
    'query': 'python',
}
url = 'https://weixin.sogou.com/weixin'
response = requests.get(url, params=params, cookies=cookies, headers=headers)

soup = BeautifulSoup(response.text, 'lxml')

h3_list = soup.select("ul[class='news-list']")[0].select("h3")
for litemp in h3_list:
    print(litemp)
    print("-------------------------------------------------")
    print(litemp.get_text())
    print("-------------------------------------------------")
    print(litemp.select("a")[0].get("href"))
    print("*" * 200)